package edu.upc.Maps;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.LocationListener;
import android.net.Uri;
import android.os.Bundle;
import com.google.android.maps.Overlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

import com.google.android.maps.MapView.LayoutParams;  


import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import android.graphics.drawable.Drawable;



public class MapsActivity extends MapActivity {
    /** Called when the activity is first created. */
	MapController mc;
    GeoPoint p,p2,p3,p4;
  
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	 MapView mapView; 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
    	Button entrarButton = (Button) findViewById(R.id.cmd_submit);
		entrarButton.setOnClickListener(new OnClickListener() {
			public void onClick(View view) {
				String latitude_source= "-12.123628";			       
				String longitude_source="-77.0060";				       
				String latitude_dest="-12.103865";				       
				String longitude_dest="-76.962984";
				
				Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+latitude_source+","+longitude_source+"&daddr="+latitude_dest+","+longitude_dest));
		        startActivity(i);
				
				
			}
		});
        
        
        
        mapView = (MapView) findViewById(R.id.mapView);
        
        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
              
        mapView.setBuiltInZoomControls(true);
        
        mc = mapView.getController();
       
        String coordinates[] = {"-12.103865", "-76.962984", "-12.087143","-77.049780","-12.074522","-77.098864","-12.095808","-76.965194"};
               
        double lat = Double.parseDouble(coordinates[0]);
        double lng = Double.parseDouble(coordinates[1]);
 
        double lat2 = Double.parseDouble(coordinates[2]);
        double lng2 = Double.parseDouble(coordinates[3]);
 
        double lat3 = Double.parseDouble(coordinates[4]);
        double lng3 = Double.parseDouble(coordinates[5]);

        double lat4 = Double.parseDouble(coordinates[6]);
        double lng4 = Double.parseDouble(coordinates[7]);

        
        List mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.pushpin);
    	        
        MyOverlay itemizedOverlay = new MyOverlay(drawable, this);
        p = new GeoPoint(
            (int) (lat * 1E6), 
            (int) (lng * 1E6));
        
        p2 = new GeoPoint(
                (int) (lat2 * 1E6), 
                (int) (lng2 * 1E6));
        
        p3 = new GeoPoint(
                (int) (lat3 * 1E6), 
                (int) (lng3 * 1E6));
        
        p4 = new GeoPoint(
                (int) (lat4 * 1E6), 
                (int) (lng4 * 1E6));
        
        OverlayItem overlayitem =  new OverlayItem(p, "Hola", "Estas en la UPC de Monterrico!");
        OverlayItem overlayitem2 =  new OverlayItem(p2, "Hola", "Estas en la UPC de Salaverry!");
        OverlayItem overlayitem3 =  new OverlayItem(p3, "Hola", "Estas en la UPC de San Miguel!");
        OverlayItem overlayitem4 =  new OverlayItem(p4, "Hola", "Estas en la UPC de la Molina. Colegio pio XII!");
        
        itemizedOverlay.addOverlay(overlayitem);
        itemizedOverlay.addOverlay(overlayitem2);
        itemizedOverlay.addOverlay(overlayitem3);
        itemizedOverlay.addOverlay(overlayitem4);
        mapOverlays.add(itemizedOverlay);
				
		MapController mc = mapView.getController();
        
        mc.animateTo(p);
        mc.setZoom(12);
       
     
       
    }
    
    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
    
   
}